package com.huawei.crm.sample.domain.product.service;

import com.huawei.crm.sample.domain.product.model.aggragate.Product;
import com.huawei.crm.sample.domain.product.repository.ProductRepository;
import org.springframework.stereotype.Service;

@Service
public class ProductDomainService {
    private final ProductRepository productRepository;

    public ProductDomainService(ProductRepository productRepository) {
        this.productRepository = productRepository;
    }

    public void checkAndDecreaseStock(String productId, int quantity) {
        Product product = productRepository.findById(productId);
        if (product == null) throw new RuntimeException("商品不存在");
        product.decreaseStock(quantity);
        productRepository.update(product);
    }
} 